Repository navigation
fix: preserve days and formatting in TimeDeltaSerializer._to_dict_value - #79
Open
reginaldalfret wants to merge 1 commit into
Open
reginaldalfret wants to merge 1 commit into
reginaldalfret wants to merge 1 commit into
Conversation
Calculate total seconds from both days and seconds so durations >= 1 day are not truncated modulo 86400s. Fix nanos division and zero-padding so fractional second strings conform to protobuf JSON duration format and round-trip cleanly through _from_dict_value. Closes Kaggle#73
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR addresses #73 by fixing the serialization of
timedeltainstances inTimeDeltaSerializer._to_dict_value.Problem
TimeDeltaSerializer._to_dict_valuepreviously useddelta.seconds, which only returns the seconds component (0..86399) modulo 86400, discardingdelta.days. Any duration of one day or more (such as a 30-hour quota:108000s) was incorrectly serialized as"21600s"(6 hours)._nanos_to_strused float division (/), producing strings like"735.0"which raised aValueErrorwhen parsed back in_from_dict_value. Sub-second values like 5ms also omitted leading zeros, serializing as"0.5s"instead of"0.005s".Solution
delta.daysanddelta.seconds._nanos_to_strmatching the Protobuf JSON duration specification (3, 6, or 9 digits).kaggle_object_tests.pyverifying durations with days, fractional seconds, microsecond zero-padding, and full round-trip serialization/deserialization.Closes #73